<template>
  <div class="nav-bar">
    <div class="list">
      <div
        v-for="(item, index) in list"
        :key="index"
        class="list-item"
        @click="handleClickItem(item)"
      >
        <div
          class="list-item-row"
          :class="{ 'active-bar': $route.path.indexOf(item.routeName) != -1 }"
          @mouseenter="onMouseenter(index)"
          @mouseleave="onMouseleave(index)"
        >
          <div class="iconfont icon">{{ item.icon }}</div>
          <!-- <div
            v-if="item.show && $route.path.indexOf(item.routeName) != -1"
            class="name-active"
          >
            {{ item.name }}
          </div>
          <div
            v-if="item.show && $route.path.indexOf(item.routeName) == -1"
            class="name"
          >
            {{ item.name }}
          </div> -->
          <div class="name">
            {{ item.name }}
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "",
  props: {
    list: {
      type: Array,
      default: () => [],
    },
  },
  mounted() {},
  methods: {
    handleClickItem(item) {
      this.$emit("change", item);
    },
    onMouseenter(index) {
      this.$emit("onMouseenter", index);
    },
    onMouseleave(index) {
      this.$emit("onMouseleave", index);
    },
  },
};
</script>

<style scoped lang="less">
.nav-bar {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  padding: 150px 0 50px 0;
  box-sizing: border-box;
  background-color: #fff;
  border-right: 1px solid #f4f7fc;
}

.list {
  width: 100%;
  .list-item {
    position: relative;
    width: 100%;
    height: 70px;
    line-height: 70px;
    user-select: none;
    cursor: pointer;
    color: #dbdbdb;
    .list-item-row {
      position: absolute;
      top: 50%;
      width: 100%;
      height: 100%;
      border-left: 5px solid #fff;
      transform: translate(0, -50%);
      box-sizing: border-box;
    }
    .icon {
      position: absolute;
      z-index: 1;
      left: 50%;
      top: -14px;
      transform: translate(-50%, 0);
      font-size: 24px;
    }
    .name {
      position: absolute;
      z-index: 999;
      left: 50%;
      top: 14px;
      transform: translate(-50%, 0);
      bottom: 0px;
      width: 100px;
      // height: 100%;
      text-align: center;
      font-size: 10px;
      color: #dbdbdb;
    }
    .name-active {
      position: absolute;
      z-index: 999;
      right: -102px;
      top: 50%;
      transform: translate(0, -50%);
      bottom: 0px;
      width: 100px;
      height: 100%;
      text-align: center;
      background-color: #d8d8d6;
      font-size: 10px;
      color: black;
    }
  }
  .active-bar {
    height: 68px;
    color: #387cf7;
    font-weight: bold;
    background-color: #f5f5f5;
    border-left: 5px solid #387cf7 !important;
    box-sizing: border-box;
    .name {
      color: #333;
    }
  }
}
</style>
